import { createRouter, createWebHistory } from 'vue-router';
import type { RouteRecordRaw } from 'vue-router';

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'Dashboard',
    component: () => import('../views/Dashboard.vue'),
    meta: { title: '仪表盘' }
  },
  {
    path: '/services',
    name: 'Services',
    component: () => import('../views/Services.vue'),
    meta: { title: '服务管理' }
  },
  {
    path: '/traces',
    name: 'Traces',
    component: () => import('../views/Traces.vue'),
    meta: { title: '链路追踪' }
  },
  {
    path: '/traces/:id',
    name: 'TraceDetail',
    component: () => import('../views/TraceDetail.vue'),
    meta: { title: '链路详情' }
  },
  {
    path: '/record',
    name: 'Record',
    component: () => import('../views/record/RecordDashboard.vue'),
    meta: { title: '记录管理' }
  },
  {
    path: '/record/services',
    name: 'RecordServices',
    component: () => import('../views/record/RecordServices.vue'),
    meta: { title: '记录服务' }
  },
  {
    path: '/record/requests',
    name: 'RecordRequests',
    component: () => import('../views/record/RecordRequests.vue'),
    meta: { title: '请求记录' }
  },
  {
    path: '/record/requests/:id',
    name: 'RecordRequestDetail',
    component: () => import('../views/record/RecordRequestDetail.vue'),
    meta: { title: '请求记录详情' }
  },
  {
    path: '/request',
    name: 'Request',
    component: () => import('../views/request/RequestDashboard.vue'),
    meta: { title: '请求管理' }
  },
  {
    path: '/request/definitions',
    name: 'RequestDefinitions',
    component: () => import('../views/request/RequestDefinitions.vue'),
    meta: { title: '请求定义' }
  },
  {
    path: '/request/definitions/create',
    name: 'RequestDefinitionCreate',
    component: () => import('../views/request/RequestDefinitionCreate.vue'),
    meta: { title: '创建请求定义' }
  },
  {
    path: '/request/definitions/:id',
    name: 'RequestDefinitionDetail',
    component: () => import('../views/request/RequestDefinitionDetail.vue'),
    meta: { title: '请求定义详情' }
  },
  {
    path: '/request/definitions/:id/execute',
    name: 'RequestDefinitionExecute',
    component: () => import('../views/request/RequestDefinitionExecute.vue'),
    meta: { title: '执行请求定义' }
  },
  {
    path: '/intercept',
    name: 'Intercept',
    component: () => import('../views/intercept/InterceptDashboard.vue'),
    meta: { title: '拦截管理' }
  },
  {
    path: '/intercept/rules',
    name: 'InterceptRules',
    component: () => import('../views/intercept/InterceptRules.vue'),
    meta: { title: '拦截规则' }
  },
  {
    path: '/faults',
    name: 'Faults',
    component: () => import('../views/Dashboard.vue'), // 临时使用Dashboard作为占位符
    meta: { title: '故障注入' }
  },
  {
    path: '/settings',
    name: 'Settings',
    component: () => import('../views/Dashboard.vue'), // 临时使用Dashboard作为占位符
    meta: { title: '系统设置' }
  }
];

const router = createRouter({
  history: createWebHistory(),
  routes
});

// 设置页面标题
router.beforeEach((to, _from, next) => {
  document.title = `${to.meta.title} - KubeRelayer` || 'KubeRelayer';
  next();
});

export default router;
